package com.snail.controller;


import com.snail.result.Result;
import com.snail.service.impl.BizCourseVideoLikeServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Date 2025/8/13 15:09
 * @Author yangming
 * @Description 点赞
 **/
@RestController
@RequestMapping("/like")
public class BizCourseVideoLikeController {
    @Autowired
    BizCourseVideoLikeServiceImpl bizCourseVideoLikeService;
    @GetMapping("/insertLike")
    public Result<String> insertLike(@RequestParam("userId")Long id,
                                                 @RequestParam("videoId") Long courseVideoId){

       bizCourseVideoLikeService.like(id,courseVideoId);
       return Result.success("点赞成功");
    }
    @GetMapping("/cancelLike")
    public Result<String> cancelLike(@RequestParam("userId")Long id,
                                         @RequestParam("videoId") Long courseVideoId){
        bizCourseVideoLikeService.cancelLike(id,courseVideoId);
        return Result.success("点赞已取消");
    }
    // 添加获取点赞数的接口
    @GetMapping("/count")
    public Result<Long> getLikeCount(@RequestParam("videoId") Long courseVideoId){
        Long count = bizCourseVideoLikeService.getLikeCount(courseVideoId);
        return Result.success(count);
    }

    @GetMapping("/hasLiked")
    public Result<Boolean> hasLiked(
            @RequestParam("userId") Long userId,
            @RequestParam("videoId") Long courseVideoId) {
        boolean liked = bizCourseVideoLikeService.hasLiked(userId, courseVideoId);
        return Result.success(liked);
    }
}
